﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

using NUnit.Framework ;
using DbSharp.Framework.CaseFile;
using DbSharp.Framework.CaseFile.Parser;
using DbSharp.Framework.DbObject;
using System.Diagnostics;
using System.Data;

namespace UnitTestProject.CaseFile
{
    [TestFixture]
    public class ProcDeclarationTest
    {
       
        [Test]
        public void TestExtractDeclarations()
        {
            string testCaseFile = @"CaseFileSample\TestCase_V2_ProcDecl_2Proc.xml";
            CaseFileNavigator fileNavigator = new CaseFileNavigator(testCaseFile);
            XElement declarationsRootElmt = fileNavigator.SelectProcDeclsRoot();
            XElement globalSettingElmt = fileNavigator.SelectGlobalSetting();

            DbConnectionConfigExtractor dbConnExtractor = new DbConnectionConfigExtractor(testCaseFile, globalSettingElmt);
            ProcedureDeclarationExtractor procDeclarationExtractor = new ProcedureDeclarationExtractor(declarationsRootElmt, dbConnExtractor);
            ProcedureDeclaration declaration;

            declaration = procDeclarationExtractor["procAlias1 "];
            Assert.AreEqual("SP_GET_JOB_COUNTRY", declaration.ProcedureName);


            declaration = procDeclarationExtractor["procAlias2 "];
            Assert.AreEqual(3, declaration.ListArgument.Count);

            Assert.AreEqual(2, procDeclarationExtractor.ListProcDeclaration.Count);

        }



        [Test,ExpectedException(typeof(DuplicateNameException))]
        public void ExtractDeclarations_UniqueName()
        {
            string testCaseFile = @"CaseFileSample\TestCase_V2_ProcDecl_SameName.xml";
            CaseFileNavigator fileNavigator = new CaseFileNavigator(@"CaseFileSample\TestCase_V2_ProcDecl_SameName.xml");
            XElement declarationsRootElmt = fileNavigator.SelectProcDeclsRoot();
            XElement globalSettingElmt = fileNavigator.SelectGlobalSetting();

            DbConnectionConfigExtractor dbConnExtractor = new DbConnectionConfigExtractor(testCaseFile, globalSettingElmt);
            
                ProcedureDeclarationExtractor procDeclarationExtractor = new ProcedureDeclarationExtractor(declarationsRootElmt, dbConnExtractor);
          
           
             
        }
    }
}
